﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using YiNing.Tools;
using YiNing.UI.Forms;

namespace Xinken
{
    public class XinkenArgs
    {
        /// <summary>
        /// mes网址
        /// </summary>
        [Category("基础参数")]
        [DisplayName("Mes网址")]
        [Description("mes请求的网址")]
        public string MesUrl { get; set; }
        /// <summary>
        /// Token
        /// </summary>
        [Category("基础参数")]
        [DisplayName("Token")]
        [Description("Mes请求的Token")]
        public string Token { get; set; }
        [Category("基础参数")]
        [DisplayName("线别名称")]
        [Description("测试线别的名称或者编号[LineName]")]
        public string LineName { get; set; }
        [Category("基础参数")]
        [DisplayName("工位名称[1]")]
        [Description("1轨道的工位名称[StationId]")]
        public string StationId { get; set; }
        [Category("基础参数")]
        [DisplayName("工位名称[2]")]
        [Description("2轨道的工位名称[StationId1]")]
        public string StationId1 { get; set; }
        [Category("基础参数")]
        [DisplayName("治具ID")]
        [Description("治具ID[FixtureId]")]
        public string FixtureId { get; set; }
        [Category("基础参数")]
        [DisplayName("站位名[1]")]
        [Description("1轨站位名[StationName]")]
        public string StationName { get; set; }
        [Category("基础参数")]
        [DisplayName("站位名[2]")]
        [Description("2轨站位名[StationName1]")]
        public string StationName1 { get; set; }

        [Category("基础参数")]
        [DisplayName("SN保存数量")]
        [Description("SN保存数量[SaveSnCount]")]
        public int SaveSnCount { get; set; }

        [Category("临时参数")]
        [DisplayName("面别")]
        [Description("面别（B或者T）[G_SIDE]")]
        public string G_SIDE { get; set; }
        [Category("临时参数")]
        [DisplayName("登录用户")]
        [Description("登录用户")]
        public string UserId { get; set; }

        [Category("基础参数")]
        [DisplayName("钢网编号")]
        [Description("钢网编号[G_StencilSN]")]
        public string G_StencilSN { get; set; }

        [Category("基础参数")]
        [DisplayName("刮刀编号")]
        [Description("刮刀编号[G_SqueegeeSN]")]
        public string G_SqueegeeSN { get; set; }

        [Category("基础参数")]
        [DisplayName("锡膏编号")]
        [Description("锡膏编号[G_SPSN]")]
        public string G_SPSN { get; set; }

        [Category("调试参数")]
        [DisplayName("是否开启日志")]
        [Description("是否开启日志[LogEnable]")]
        public bool LogEnable { get; set; }

        /// <summary>
        /// 保存自己
        /// </summary>
        public void SaveThis()
        {
            JsonHelper.Serialize(this, GetThisFileName());
        }

        /// <summary>
        /// 加载配置
        /// </summary>
        /// <returns></returns>
        public static XinkenArgs LoadThis()
        {
            var res = JsonHelper.DeserializeByFile<XinkenArgs>(GetThisFileName());
            if (res == null)
            {
                DarkMessageBox.ShowWarning("加载配置文件异常,参数初始化");
                res = new XinkenArgs();
            }
            return res;
        }
        /// <summary>
        /// 获取本身的文件名
        /// </summary>
        /// <returns></returns>
        public static string GetThisFileName()
        {
            string name = "Plugins/XinkenSpi/config.zyn";
            return Path.Combine(System.AppDomain.CurrentDomain.BaseDirectory, name);
        }


    }
}
